{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=3394
  Verdict: Accepted
}
uses SysUtils, Math;
const big=round(1e9);
type ar = array[-10..300010] of longint;
var     i,n,tt,t,a,b,c,y,p,m,res,resa,resb,resc,ca,cc,j,cr,cb:longint;
        sm:array[0..2] of ar;
        sn:array[0..2] of longint;
        d:array[1..2,1..5] of longint;
procedure get(a1,b1,c1:longint);
var r:longint;
begin
if not((a1>=1) and (a1<sn[0]-1)) then exit;
if not((b1>=1) and (b1<sn[1]-1)) then exit;
if not((c1>=1) and (c1<sn[2]-1)) then exit;
if (sm[0][a1-1]<sm[1][b1-1]) or (sm[1][b1-1]<sm[2][c1-1]) then exit;
r:=abs(a1-a)+abs(b1-b)+abs(c1-c);
if res>=r then begin
   res:=r;
   resa:=a1;
   resb:=b1;
   resc:=c1;
end;
end;
procedure sort(var a:ar; l,r:longint);
var i,j,x,y:longint;
begin
i:=l;
j:=r;
x:=a[(l+r) div 2];
repeat
        while a[i]>x do inc(i);
        while a[j]<x do dec(j);
        if i<=j then begin
                y:=a[i];
                a[i]:=a[j];
                a[j]:=y;
                inc(i);
                dec(j);
        end;
until i>j;
if l<j then sort(a,l,j);
if i<r then sort(a,i,r);
end;
begin
assign(input,'input.txt');
assign(output,'output.txt');
reset(input);
rewrite(output);
read(tt);
for t:=1 to tt do begin
        for i:=0 to 2 do sn[i]:=0;
        read(a,b,c,n);
        for i:=1 to n do begin
                read(y,p);
                dec(y,1994);
                sm[y][sn[y]]:=p;
                inc(sn[y]);
        end;
        for i:=0 to 2 do begin
            sm[i][sn[i]]:=-1; inc(sn[i]);
            sm[i][sn[i]]:=-1; inc(sn[i]);
            sort(sm[i],0,sn[i]-1);
        end;
        res:=big;
        resa:=0;
        resb:=0;
        resc:=0;
        ca:=0;
        cc:=1;
        for i:=0 to sn[1]-1 do begin
            cb:=i+1;
            while sm[2][cc]>sm[1][i] do inc(cc);
            while sm[0][ca]>sm[1][i] do inc(ca);
            d[1][1]:=cc-1;
            d[1][2]:=cc;
            d[1][3]:=cc+1;
            d[1][4]:=c;
            d[1][5]:=sn[2]-2;
            d[2][1]:=ca-1;
            d[2][2]:=ca;
            d[2][3]:=ca+1;
            d[2][4]:=a;
            d[2][5]:=1;
            for j:=1 to 5 do begin
                get(a+b+c-(cb+d[1][j]),cb,d[1][j]);
                get(d[2][j],cb,a+b+c-(cb+d[2][j]));
            end;
        end;
        if res=big then writeln(-1) else writeln(res,' ',resa,' ',resb,' ',resc);
end;
end.